$(function () {

    $("body").css("opacity","1")

    $("#chaxun").click(function(){
        console.log(1);
        $(this).css({"background-color":"#007dd2","color":"white"})
        $("#gaibian").css({"background-color":"white","color":"black"})
        $("#chaxun1").show(500)  
        $("#gaibian1").hide(500)  
    });

    $("#gaibian").click(function(){
        console.log(1);
        $(this).css({"background-color":"#007dd2","color":"white"})
        $("#chaxun").css({"background-color":"white","color":"black"})
        $("#gaibian1").show(500)  
        $("#chaxun1").hide(500)  
    });


    var username = localStorage.getItem("username");

    $.post("/xjxt/jschaxun?username="+ username +"",function(res){

        var hehe = JSON.parse(res);
        console.log(hehe);

        //动态的创建一个table，同时将后台获取的数据动态的填充到相应的单元格
        $("#xjchaxun").append("<tr>"+ "<td>" + "姓名" +"</td>" + "<td>" + "学号" + "</td>" + "<td>" + "申请类型" + "</td>" + "<td>" + "具体原因"+"</td>" +"<td>" + "状态" +"</td>"+"</tr>");
        $.each(hehe, function (colIndex, col) {

            if (col.gaibian == "01")
            {col.gaibian = "在读"}

            if (col.gaibian == "02")
            {col.gaibian = "休学"}

            if (col.gaibian == "03")
            {col.gaibian = "当兵"}

            if (col.gaibian == "04")
            {col.gaibian = "病休"}

            if (col.gaibian == "05")
            {col.gaibian = "延期"}

            if (col.queren == "0")
            {col.queren = "尚未处理"}

            if (col.queren == "1")
            {col.queren = "同意改变"}

            if (col.queren == "2")
            {col.queren = "不同意改变"}
            var th;
            th+="<td>" + col.name+"</td>"+  "<td id='"+ col.username +"'>" +"<a href='#'>" + col.username + "</a>" +"</td>"  + "<td>" +col.gaibian+"</td>" + "<td>" +col.neirong+"</td>" + "<td>" +col.queren+"</td>";
            $("#xjchaxun").append("<tr>" + th + "</tr>");

            $("#"+col.username+"").click(function(){
                $.post("/xjxt/xuejizhuangtai?username="+ col.username +"",function(res){

                    var hehe = JSON.parse(res);
                    console.log(hehe);
                    $("#knumber").html(hehe[0].knumber);
                    $("#xnumber").html(hehe[0].xnumber);
                    $("#name").html(hehe[0].name);
                    $("#sex").html(hehe[0].sex);
                    $("#birthday").html(hehe[0].birthday);
                    $("#ID").html(hehe[0].ID);
                    $("#nation").html(hehe[0].nation);
                    $("#school").html(hehe[0].school);
                    $("#nschool").html(hehe[0].nschool);
                    $("#inday").html(hehe[0].inday);
                    $("#zhuangtai").html(hehe[0].zhuangtai);
                    $("#name12").val(hehe[0].name);
                    $("#username").val(hehe[0].username);
                    $("#touxiang").attr("src",hehe[0].touxiang);

                });

                $.post("/xjxt/xuejichaxun?username="+ col.username +"",function(res){

                    var hehe = JSON.parse(res);
                    console.log(hehe);
                    if (hehe[0].gaibian == "01")
                    {hehe[0].gaibian = "在读"}

                    if (hehe[0].gaibian == "02")
                    {hehe[0].gaibian = "休学"}

                    if (hehe[0].gaibian == "03")
                    {hehe[0].gaibian = "当兵"}

                    if (hehe[0].gaibian == "04")
                    {hehe[0].gaibian = "病休"}

                    if (hehe[0].gaibian == "05")
                    {hehe[0].gaibian = "延期"}
                    console.log(hehe[0].gaibian);
                    $("#gaibian2").html(hehe[0].gaibian);
                    $("#gaibian3").val(hehe[0].gaibian);
                    $("#shengq").html(hehe[0].neirong);


                });
                $("#gaibian1").show(500)  
                $("#chaxun1").hide(500)  
                $("#gaibian").css({"background-color":"#007dd2","color":"white"})
                $("#chaxun").css({"background-color":"white","color":"black"})

                window.location.reload()

            });

        });
    });
});